<?php echo CHtml::beginForm(); ?>

<?php


$cs = Yii::app()->clientScript;

echo CHtml::activeHiddenField($model, 'project_id') . "\n";
echo CHtml::activeHiddenField($model, 'id') . "\n";
$form_name = 'ObjectiveForm[objectives]';
?>

<h2><?php echo Yii::t('project', 'Previous objectives'); ?></h2>
<div class="yiiForm" id="project_topic">
<ul id="objectives">
<?php

foreach ($model->objectives as $topic) {
	echo "<li id='node_" . $topic->id . "'>" . $topic->topic->label . "</li>";
	$this->widget('adviser.widgets.CommentLayer', array (
		'topic_id' => $topic->id,
		'columns' => 60,
		'rows' => 5,
		'prefix' => '',
		'adviser_validation' => $topic->adviser_validation,
		'adviser_topic_validation' => $topic->adviser_validation_topic,
		'adviser_has_error' => count($model->getErrors('adviser_validation_' . $topic->id)) > 0,
		'owner_validation' => $topic->owner_validation,
		'owner_topic_validation' => $topic->owner_validation_topic,
		'owner_has_error' => count($model->getErrors('owner_validation_' . $topic->id)) > 0,
		'comment' => $topic->validation_comments,
		'form_name' => $form_name
	));
}
?>
</ul>
</div><!-- yiiForm -->
<div class="action">
<?php echo CHtml::submitButton(Yii::t('views', 'Next >'), array('name' => 'next_button')); ?>
</div>

<?php


echo CHtml::endForm();

$script =<<<JS
$("div[id^='comment_layer_']").hide();

$("li[id^='node_']").each(function(index){
	keyId = this.id.replace('node_', '');
	t = $(this);
	t.html("<a id='link_comment_layer_"+keyId+"'>"+t.text()+"</a>")
	 .prepend('<img id="img_comment_'+keyId+'" src="images/arrow_down_blue.png" />')
	 .click(function(event){
		keyId = this.id.replace('node_', '');
		if (
			event.target.id == "node_"+keyId ||
			event.target.id == "img_comment_"+keyId ||
			event.target.id == "link_comment_layer_"+keyId
		){
			$("#img_comment_"+keyId).click();
		}
	 });
	$("#img_comment_"+keyId).toggle(
		function(){
			keyId = this.id.replace('img_comment_', '');
			this.src = 'images/arrow_up_blue.png';
			$("#comment_layer_"+keyId).show();
		},
		function(){
			keyId = this.id.replace('img_comment_', '');
			this.src = 'images/arrow_down_blue.png';
			$("#comment_layer_"+keyId).hide();
		}
	);
});

JS;
$cs->registerScript('topics_form_save', $script);
$cs->registerScriptFile(Yii::app()->baseUrl . '/js/masks.js', CClientScript::POS_HEAD);
$cs->registerScriptFile(Yii::app()->baseUrl . '/js/topic_validation.js', CClientScript::POS_HEAD);
?>
